<?php

/**
 * This file is part of the Codizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Codizer Core Team <team@codizer.org>
 * @package     Codizer
 */

abstract class f_core_Service
{
	/**
	 * Get document provider instance
	 * 
	 * @return f_document_Provider
	 */
	public function getDocumentProvider()
	{
		return f_document_Provider::getInstance();
	}
	
	/**
	 * Get the current context
	 *
	 * @return f_core_Context
	 */
	public function getContext()
	{
		return f_core_Context::getInstance();
	}
	
	/**
	 * Get the current context lang
	 *
	 * @return string
	 */
	public function getContextLang()
	{
		return $this->getContext()->getLang();
	}
	
	/**
	 * Get the current session instance
	 *
	 * @return f_core_Session
	 */
	public function getSession()
	{
		return f_core_Session::getInstance();
	}
	
	/**
	 * Get the current user context
	 *
	 * @return f_context_User
	 */	
	public function getUserContext($context = "")
	{
		return f_context_User::getInstance($context);
	}
	
	/**
	 * Get the current user setted in user context
	 *
	 * @return mixed
	 */
	public function getUser($context = "")
	{
		return f_context_User::getInstance($context)->getUser();
	}

	/**
	 * Check if the current user has the given right
	 *
	 * @param string $ruleName
	 * @return boolean
	 */
	public function userHasRight($ruleName)
	{
		return $this->getUserContext()->hasRight($ruleName);
	}

	/**
	 * Put datas in a cache file
	 *
	 * @param string $key
	 * @param mixed $datas
	 * @param integer $timeOut
	 * @return boolean
	 */
	public function putInCache($key, $datas, $timeOut = null)
	{
		return f_core_Cache::getInstance()->putInCache($key, $datas, $timeOut);
	}
	
	/**
	 * Check if there is a cache file with the given key
	 *
	 * @param string $key
	 * @return boolean
	 */
	public function hasCache($key)
	{
		return f_core_Cache::getInstance()->hasCache($key);
	}
	
	/**
	 * Get cache file content if valid
	 *
	 * @param string $key
	 * @param mixed $defaultValue
	 * @return mixed
	 */
	public function getCacheContent($key, $defaultValue = null)
	{
		return f_core_Cache::getInstance()->getCacheContent($key, $defaultValue);
	}

	/**
	 * Log to FirePHP extension
	 *
	 * @param mixed $logObject
	 * @param string $logName
	 */
	public function fireLog($logObject, $logName = null)
	{
		$firePHPLogger = f_logs_Logger::getInstance()->getFirePHPLogger();
		
		if(!is_null($firePHPLogger))
		{
			$firePHPLogger->log($logObject, $logName);
		}
	}
	
	/**
	 * Log to FirePHP extension
	 *
	 * @param mixed $logObject
	 * @param string $logName
	 */	
	public function fireInfo($logObject, $logName = null)
	{
		$firePHPLogger = f_logs_Logger::getInstance()->getFirePHPLogger();
		
		if(!is_null($firePHPLogger))
		{
			$firePHPLogger->info($logObject, $logName);
		}
	}
	
	/**
	 * Log to FirePHP extension
	 *
	 * @param mixed $logObject
	 * @param string $logName
	 */	
	public function fireError($logObject, $logName = null)
	{
		$firePHPLogger = f_logs_Logger::getInstance()->getFirePHPLogger();
		
		if(!is_null($firePHPLogger))
		{
			$firePHPLogger->error($logObject, $logName);
		}
	}
	
	/**
	 * Log to FirePHP extension
	 *
	 * @param mixed $logObject
	 * @param string $logName
	 */	
	public function fireWarn($logObject, $logName = null)
	{
		$firePHPLogger = f_logs_Logger::getInstance()->getFirePHPLogger();
		
		if(!is_null($firePHPLogger))
		{
			$firePHPLogger->info($logObject, $logName);
		}
	}		
}